/* 选择房间 **/
define(function(require,exports,module){
	var HandlerBars = require("handlebars");
	var typeTpl = require("../../../roompanorama/src/assets/tpl/roompanorama_type.tpl");
	var roomTpl = require("../../../roompanorama/src/assets/tpl/roompanorama_room.tpl");
	require("../../../roompanorama/src/assets/css/roompanorama_main.css")
	var roomPanoramaEvents = require("../../../roompanorama/src/handler/events");
	
	module.exports = {
		showRooms:function(index,idata){
			var html = HandlerBars.compile(typeTpl)();
    		$(".J-status",this.element).html(html);
			var that = this;
    		var subnav=this.get("subnav");
    		
    		that.set("editGridIndex",index);
    		
    		subnav.load("building", {
				params:{
	            	servicePoint: subnav.getValue("servicePoint"),
	            	fetchProperties:"pkOrgBuilding,name"
	            },
                callback: function(data) {
                    subnav.setData("building", data);
                    subnav.load("roomType", {
        				params:{
        					orgBuilding: subnav.getValue("building"),
        	            	fetchProperties:"*"
        	            },
                        callback: function(data) {
                            subnav.setData("roomType", data);
                            that.changeImg("clean","1jingfang_chose.png");
                            that.setData("Clear",that);
                        }
                    });
                }
            });
		},
		changeImg:roomPanoramaEvents.changeImg,
        print:roomPanoramaEvents.print,
        setData:roomPanoramaEvents.setData,
        setRoomPersonInfo:roomPanoramaEvents.setRoomPersonInfo,
        renderRoomNumber:roomPanoramaEvents.renderRoomNumber,
        selectPersonInfo:roomPanoramaEvents.selectPersonInfo,
        selectRoom:function(e){
        	// 选择房间后返回界面并进行处理
        	var pkRoom = $(e.currentTarget).attr("data-pkRoom");
        	var code = $(e.currentTarget).attr("data-code");
        	var pkRoomType = this.get("subnav").getValue("roomType");
        	var roomTypeName = this.get("subnav").getText("roomType");
        	
        	var index = this.get("editGridIndex");
        	var gridObj = this.get("editgrid");
        	var sdata = gridObj.getData(index);
        	if(!sdata.croomType){
        		sdata.croomType = {};
        	}
        	sdata.croomType["pkRoomType"] = pkRoomType;
        	sdata.croomType["name"] = roomTypeName;
        	
        	if(!sdata.croom){
        		sdata.croom = {};
        	}
        	sdata.croom["pkRoom"] = pkRoom;
        	sdata.croom["code"] = code;
        	sdata.change = true;
        	
        	gridObj.update(index,sdata);
        	
        	this.hide([".J-roomStatus"]).show([".J-form",".J-editgrid "]);
        	this.get("subnav").hide(["building","roomType","roomStateReturn"]).show(["save","return"]);
        	
        },
        events:function(){
    		return roomPanoramaEvents.events;
    	},
		
	};
});
